package com.mypro.bookcity.servlet;

import com.mypro.bookcity.dao.UserDao;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = {"/user/regist"})
public class RegistServlet extends GenericServlet {
    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;

        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String email = request.getParameter("email");

        System.out.println(username+"  "+password+"  "+email);

        UserDao ud = new UserDao();
        boolean s = ud.addUser(username,password,email);

        System.out.println(s);

        if(s==true){
            response.sendRedirect("/pages/user/regist_success.html");

        }else{
            response.sendRedirect("/pages/user/login.html");
        }

    }
}
